{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e12883f3-0197-4fdb-af37-99cd9a8864f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "from dotenv import load_dotenv\n",
    "load_dotenv()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "73497434",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A 与 B 的余弦相似度: 0.9872411207126469\n",
      "B 与 C 的余弦相似度: 0.6050832675335579\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "def cosine_similarity(a, b):\n",
    "    \"\"\"余弦相似度\"\"\"\n",
    "    return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))\n",
    "\n",
    "# 示例向量\n",
    "a = np.array([0.2, 0.8])\n",
    "b = np.array([0.3, 0.7])\n",
    "c = np.array([0.8, 0.2])\n",
    "\n",
    "print(f\"A 与 B 的余弦相似度: {cosine_similarity(a, b)}\")\n",
    "print(f\"B 与 C 的余弦相似度: {cosine_similarity(b, c)}\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "AI工程化(week03)",
   "language": "python",
   "name": "week03"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
